close all; clear all; path(pathdef); clc;

% add subfunctions
addpath(genpath('subfunctions/'))
addpath(genpath('data_suppinfo/'))

% color library
color_list{1} = [67 84 147]/255;        % dark blue
color_list{2} = [110 153 201]/255;      % light blue
color_list{3} = [196 40 27]/255;        % dark red
color_list{4} = [218 134 121]/255;      % light red
color_list{5} = [40 127 70]/255;        % dark green
color_list{6} = [161 196 139]/255;      % light green
color_list{7} = [218 165 32]/255;       % gold
color_list{8} = [238 221 130]/255;      % light gold
color_list{9} = [128 0 128]/255;        % purple
color_list{10} = [204 153 255]/255;     % light purple
color_list{11} = [161 165 162]/255;     % grey

%% Heat gradient

%%% data list as a function of laser power %%%
data{1} = load('data50.mat');
data{2} = load('data100.mat');
data{3} = load('data150.mat');
data{4} = load('data200.mat');

fh = figure(1); cla()
set(fh, 'position', [100 100 [180 230]])
cla()

% IR calibration
LD_reading                  = [0 25 50 100 150 200 250]; % mA
Power_mW_before_obj         = [0 0.92 3.85 9.92 15.9 21.9 27.8]; % mW
transmission                = 0.35;
mA_to_mW                    = fitplot({LD_reading(2:end), Power_mW_before_obj(2:end)}, 'linear', 'noplot');
Pow_vals                    = transmission * mA_to_mW([150 100 50]);

IR_power_str    = cell(1,3);
for ii = 1:3
    IR_power_str{ii} = [mat2str(round(10*Pow_vals(ii))/10), ' mW'];
end

bPlotOption.MarkerSize  = 4;
bPlotOption.CapSize     = 0;
bPlotOption.LineWidth   = 1;
bPlotOption.FontSize    = 12;
bPlotOption.MarkerList = {'o', 's', 'd', '>', 'x'};
color_index             = [1 7 3];
for ii = 3:-1:1
    plot(data{ii}.tempdata.x_sim, data{ii}.tempdata.y_sim, 'color', color_list{color_index(ii)}, 'linewidth', bPlotOption.LineWidth, 'handlevisibility', 'off')
    hold on
    plotcustom(data{ii}.tempdata.x_exp,data{ii}.tempdata.y_exp,data{ii}.tempdata.yerr_exp, bPlotOption, ii, color_index(ii))
end
set(gca, 'XTick', [0 10 20])
set(gca, 'YTick', [0 5 10 15])
axisinfo('Distance (\mum)', '\DeltaT (K)', [0 20], [0 16], 12)
legend(IR_power_str, 'location', 'northeast')
legend boxoff

%% Heat scan

load('HeatScanData-2017-11-17_21-32-24/gResultData.mat');

xdata = gResultData.X_scan / 0.0081;
ydata_on = gResultData.map2D_heat_all;
ydata_off = gResultData.map2D_back_all;
ydata_diff = gResultData.map2D_diff_all;
ydataerr_on = gResultData.map2D_heat_err_all;
ydataerr_off = gResultData.map2D_back_err_all;
ydataerr_diff = gResultData.map2D_diff_err_all;

fh = figure(2); 
set(fh, 'position', [100 100 [190 187]])
cla()
MarkerList  = {'o', 's', 'd', '>', 'x'};
offset      = 6;
for ii = 1:4
    errorbar(xdata, ydata_on(:,1,ii)+offset, ydataerr_on(:,1,ii), '.', 'capsize', 0, 'linewidth', 2, 'color', color_list{3}, 'handlevisibility', 'off')
    hold on
    errorbar(xdata, ydata_off(:,1,ii)+offset, ydataerr_off(:,1,ii), '.', 'capsize', 0, 'linewidth', 2, 'color', color_list{1}, 'handlevisibility', 'off')

    plot(xdata, ydata_on(:,1,ii)+offset, '-', 'linewidth', 1, 'marker', MarkerList{ii}, 'markersize', 5, 'color', color_list{4}, 'MarkerFaceColor', color_list{4}, 'MarkerEdgeColor', color_list{3})
    plot(xdata, ydata_off(:,1,ii)+offset, '-', 'linewidth', 1, 'marker', MarkerList{ii}, 'markersize', 5, 'color', color_list{2}, 'MarkerFaceColor', color_list{2}, 'MarkerEdgeColor', color_list{1})
end
t1 = text(-24, 14, 'IR on');
t1.FontSize = 12;
t1.Color = color_list{3};

t2 = text(-1, 2.5, 'IR off');
t2.FontSize = 12;
t2.Color = color_list{1};

set(gca, 'XTick', [-40 0 40])
set(gca, 'YTick', [-5 0 5 10 15])
axisinfo('Distance (\mum)', '\deltaT_{on}, \deltaT_{off} (K)', [-40 55], [-5 17], 12)

fh = figure(3); 
set(fh, 'position', [100 400 [170 185]])
cla()
for ii = 1:4
    errorbar(xdata, ydata_diff(:,1,ii), ydataerr_diff(:,1,ii), '.', 'capsize', 0, 'linewidth', 2, 'color', color_list{5}, 'handlevisibility', 'off')
    hold on
    plot(xdata, ydata_diff(:,1,ii), '-', 'linewidth', 1, 'marker', MarkerList{ii}, 'markersize', 5, 'color', color_list{5}, 'MarkerFaceColor', color_list{6})
end
set(gca, 'XTick', [-40 0 40])
set(gca, 'YTick', [0 5 10 15 20])
axisinfo('Distance (\mum)', '\DeltaT (K)', [-45 45], [4 17], 12)




